// ui_dictionary.h
#ifndef UI_DICTIONARY_H
#define UI_DICTIONARY_H

#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QTextBrowser>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QLabel>
#include <QtWidgets/QFrame>

class Ui_Dictionary
{
public:
    // 主布局组件
    QVBoxLayout *mainLayout;
    QFrame *mainFrame;

    // 顶部搜索栏
    QFrame *searchFrame;
    QHBoxLayout *searchLayout;
    QLineEdit *searchEdit;
    QPushButton *searchButton;

    // 主体内容区域
    QHBoxLayout *contentLayout;

    // 左侧功能区（黄金比例1:1.618，约340px宽度）
    QVBoxLayout *leftPanelLayout;
    QFrame *wordListFrame;
    QListWidget *wordList;
    QPushButton *historyButton;  // 仅保留的历史记录按钮

    // 右侧释义区域
    QFrame *definitionFrame;
    QVBoxLayout *definitionLayout;
    QLabel *definitionTitle;
    QTextBrowser *definitionText;

    void setupUi(QWidget *Dictionary)
    {
        // 主窗口设置
        Dictionary->setObjectName("Dictionary");
        Dictionary->resize(900, 650);
        Dictionary->setMinimumSize(900, 650);
        Dictionary->setMaximumSize(900, 650);
        Dictionary->setStyleSheet("QWidget#Dictionary { background-color: #f8f9fa; }");

        // 主布局
        mainLayout = new QVBoxLayout(Dictionary);
        mainLayout->setContentsMargins(0, 0, 0, 0);
        mainLayout->setSpacing(0);

        mainFrame = new QFrame(Dictionary);
        mainFrame->setStyleSheet("background-color: white; border-radius: 8px;");
        mainLayout->addWidget(mainFrame);

        QVBoxLayout *frameLayout = new QVBoxLayout(mainFrame);
        frameLayout->setContentsMargins(15, 15, 15, 15);
        frameLayout->setSpacing(15);

        // ===== 顶部搜索栏 =====
        searchFrame = new QFrame(mainFrame);
        searchFrame->setStyleSheet(
            "QFrame {"
            "  background-color: #4a8cff;"
            "  border-radius: 6px;"
            "  padding: 10px;"
            "}"
        );

        searchLayout = new QHBoxLayout(searchFrame);
        searchLayout->setContentsMargins(5, 5, 5, 5);
        searchLayout->setSpacing(10);

        // 搜索输入框
        searchEdit = new QLineEdit(searchFrame);
        searchEdit->setPlaceholderText("输入要查询的单词...");
        searchEdit->setStyleSheet(
            "QLineEdit {"
            "  border: 2px solid #d6e4ff;"
            "  border-radius: 4px;"
            "  padding: 8px 12px;"
            "  font-size: 15px;"
            "  background-color: white;"
            "  color: #333;"
            "}"
            "QLineEdit:focus {"
            "  border-color: #80b0ff;"
            "}"
        );

        // 搜索按钮
        searchButton = new QPushButton(searchFrame);
        searchButton->setText("搜索");
        searchButton->setStyleSheet(
            "QPushButton {"
            "  background-color: #2a7cff;"
            "  color: white;"
            "  border: none;"
            "  border-radius: 4px;"
            "  padding: 8px 16px;"
            "  font-size: 14px;"
            "  min-width: 60px;"
            "}"
            "QPushButton:hover {"
            "  background-color: #1a6cff;"
            "}"
            "QPushButton:pressed {"
            "  background-color: #0a5cff;"
            "}"
        );

        searchLayout->addWidget(searchEdit, 1);
        searchLayout->addWidget(searchButton);
        frameLayout->addWidget(searchFrame);

        // ===== 主体内容区域 =====
        contentLayout = new QHBoxLayout();
        contentLayout->setSpacing(15);

        // 左侧功能面板（固定宽度340px）
        leftPanelLayout = new QVBoxLayout();
        leftPanelLayout->setSpacing(15);
        leftPanelLayout->setContentsMargins(0, 0, 0, 0);

        // 单词列表
        wordListFrame = new QFrame();
        wordListFrame->setStyleSheet(
            "QFrame {"
            "  background-color: white;"
            "  border: 1px solid #e1e5eb;"
            "  border-radius: 6px;"
            "}"
        );

        QVBoxLayout *wordListInnerLayout = new QVBoxLayout(wordListFrame);
        wordListInnerLayout->setContentsMargins(0, 0, 0, 0);
        wordListInnerLayout->setSpacing(0);

        QLabel *wordListTitle = new QLabel("单词列表");
        wordListTitle->setStyleSheet(
            "QLabel {"
            "  font-size: 16px;"
            "  font-weight: bold;"
            "  color: #4a8cff;"
            "  padding: 10px 15px;"
            "  border-bottom: 1px solid #e1e5eb;"
            "}"
        );
        wordListInnerLayout->addWidget(wordListTitle);

        wordList = new QListWidget();
        wordList->setStyleSheet(
            "QListWidget {"
            "  border: none;"
            "  font-size: 14px;"
            "  color: #333;"
            "}"
            "QListWidget::item {"
            "  padding: 8px 15px;"
            "  border-bottom: 1px solid #f0f2f5;"
            "}"
            "QListWidget::item:hover {"
            "  background-color: #f5f8ff;"
            "}"
            "QListWidget::item:selected {"
            "  background-color: #e1ebff;"
            "  color: #2a7cff;"
            "}"
        );
        wordListInnerLayout->addWidget(wordList, 1);
        leftPanelLayout->addWidget(wordListFrame, 1);

        // 历史记录按钮（单独放在单词列表下方）
        historyButton = new QPushButton();
        historyButton->setIcon(QIcon(":/icons/history.png"));
        historyButton->setText("历史记录");
        historyButton->setStyleSheet(
            "QPushButton {"
            "  background-color: white;"
            "  color: #666;"
            "  border: 1px solid #e1e5eb;"
            "  border-radius: 6px;"
            "  padding: 10px 15px;"
            "  font-size: 14px;"
            "  text-align: left;"
            "}"
            "QPushButton:hover {"
            "  color: #4a8cff;"
            "  background-color: #f5f8ff;"
            "}"
        );
        leftPanelLayout->addWidget(historyButton);

        // 左侧面板整体
        QFrame *leftPanel = new QFrame();
        leftPanel->setFixedWidth(340);
        leftPanel->setLayout(leftPanelLayout);
        contentLayout->addWidget(leftPanel);

        // 右侧释义区域
        definitionFrame = new QFrame();
        definitionFrame->setStyleSheet(
            "QFrame {"
            "  background-color: white;"
            "  border: 1px solid #e1e5eb;"
            "  border-radius: 6px;"
            "}"
        );

        definitionLayout = new QVBoxLayout(definitionFrame);
        definitionLayout->setContentsMargins(0, 0, 0, 0);
        definitionLayout->setSpacing(0);

        definitionTitle = new QLabel("释义");
        definitionTitle->setStyleSheet(
            "QLabel {"
            "  font-size: 18px;"
            "  font-weight: bold;"
            "  color: #4a8cff;"
            "  padding: 10px 15px;"
            "  border-bottom: 1px solid #e1e5eb;"
            "}"
        );
        definitionLayout->addWidget(definitionTitle);

        definitionText = new QTextBrowser();
        definitionText->setStyleSheet(
            "QTextBrowser {"
            "  border: none;"
            "  font-size: 15px;"
            "  color: #333;"
            "  padding: 15px;"
            "  line-height: 1.5;"
            "}"
        );
        definitionLayout->addWidget(definitionText, 1);
        contentLayout->addWidget(definitionFrame, 1);

        frameLayout->addLayout(contentLayout, 1);
    }
};

namespace Ui {
    class Dictionary: public Ui_Dictionary {};
} // namespace Ui

#endif // UI_DICTIONARY_H